<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/9
  Time: 13:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Title</title>
    <script src="jq/jquery.js"></script>
</head>
<body>
    <h1 align="center">添加元宇宙商品</h1>
    <form action="MetaverseProductAdd" method="post">
        <table align="center" border="1px" style="background: lightgray">
            <tr>
                <td width="150px">商品名称：</td>
                <td width="500px"><input id="name" name="name" type="text"></td>
            </tr>
            <tr>
                <td>商品描述：</td>
                <td><textarea id="desc" name="desc" style="width: 250px;height: 150px"></textarea></td>
            </tr>
            <tr>
                <td>商品价格：</td>
                <td><input type="text" id="price" name="price"></td>
            </tr>
            <tr>
                <td>商品状态：</td>
                <td><input type="radio" id="flag" name="flag" value="1" checked>上架 <input value="0" id="flag2" name="flag" type="radio">下架</td>
            </tr>
            <tr>
                <td>操作：</td>
                <td><input type="submit" value="新增"> <input type="button" onclick="reset()" value="重置"></td>
            </tr>
        </table>
    </form>
</body>
<script>
    function reset() {
        $("#name").val("");
        $("#desc").val("");
        $("#price").val("");
        $("#flag").checked=true;
    }

    //单击“提交”按钮提交表单
    $('form').submit(function(){
        var flag=true;
        if(!CheckName()) flag=false;
        else if(!CheckDesc()) flag=false;
        else if(!CheckPrice()) flag=false;
        return flag;
    })

    function CheckName(){
        var name=$('#name').val();
        if(name==""){
            alert("商品名称不能为空")
            return false;
        }
        return true;
    }

    function CheckDesc() {
        var desc = $('#desc').val();
        if(desc == ""){
            alert("商品描述不能为空")
            return false;
        }
        return true;
    }

    function CheckPrice() {
        var price = $('#price').val();
        if (price == "") {
            alert("商品价格不能为空")
            return false;
        }else if(isNaN(parseInt(price)) || parseInt(price) < 10){
            alert("商品价格必须是保留2位小数")
            return false;
        }
        return true;
    }
</script>
</html>
